package yx.action;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;

import yx.service.PaperServiceInt;
import yx.vo.JsonVO;
import yx.vo.PaperVO;

import com.opensymphony.xwork2.ModelDriven;

@ParentPackage("basePackage")
@Namespace("/")
@Action(value = "paperAction")
public class PaperAction extends BaseAction implements ModelDriven<PaperVO> {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(PaperAction.class);

	private PaperVO paper = new PaperVO();

	@Override
	public PaperVO getModel() {
		return paper;
	}

	private PaperServiceInt paperService;

	public PaperServiceInt getPaperService() {
		return paperService;
	}

	@Autowired
	public void setPaperService(PaperServiceInt paperService) {
		this.paperService = paperService;
	}

	public void queryPaper() {
		super.writeJson(paperService.datagrid(paper));
	}

	public void addPaper() {
		JsonVO j = new JsonVO();
		try {
			PaperVO u = paperService.save(paper);
			j.setSuccess(true);
			j.setMsg("增加成功！");
			j.setObj(u);
		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void removePaper() {
		paperService.remove(paper.getIds());
		JsonVO j = new JsonVO();
		j.setSuccess(true);
		j.setMsg("删除成功！");
		super.writeJson(j);
	}

	public void editPaper() {
		PaperVO u = paperService.edit(paper);
		JsonVO j = new JsonVO();
		j.setSuccess(true);
		j.setMsg("编辑成功！");
		j.setObj(u);
		super.writeJson(j);
	}

}
